<!DOCTYPE html>
<html>

{include file='public/header'}

<body>
    <div class="x-nav">
        <span class="layui-breadcrumb">
            <a href="javascript:void(0)">首页</a>
            <a href="javascript:void(0)">活动管理</a>
            <a><cite>活动列表</cite></a>
        </span>
        <a class="layui-btn layui-btn-small" id="reload" title="刷新">
            <i class="layui-icon" style="line-height:30px"><i class="iconfont">&#xe6aa;</i></i>
        </a>
    </div>
    <div class="x-body">
        <form class="layui-form layui-row" style="margin-top:15px;margin-bottom: 10px;">
            <div class="layui-inline">
                <label class="layui-form-label w-auto">活动名称：</label>
                <div class="layui-input-inline">
                    <input type="text" name="name" placeholder="请输入活动名称" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline" style="margin-left:10px">
                <button class="layui-btn" lay-submit lay-filter="searchList">搜索</button>
                <button type="reset" id="resetList" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </form>

        <table id="activity_list" lay-filter="activity_list"></table>
    </div>
    <script type="text/html" id="toolbarDemo">
        <div class="layui-btn-container">
            <button class="layui-btn layui-btn-sm" lay-event="add">添加活动</button>
        </div>
    </script>
    <script type="text/html" id="tbBar">
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script>
    <script>
        let params = {
            elem: '#activity_list'
            , toolbar: '#toolbarDemo'
            , url: '/admin/activity/list' //数据接口
            , id: 'activity_list'
            , limit:15
            , page:true
            , cols: [[ //表头
                { field: 'id', title: 'ID', width: 80, sort: true, align:'center', width:90}
                , { field: 'name', title: '活动名称', align:'center', width:120}
                , {
                    field: 'cover_img', title: '封面图片',align:'center',width:120, templet: function (d) {
                        if (d.cover_img) {
                            return `<div class="layer-photos" style="cursor:pointer;height: 100%;">
                                    <img onclick="showimg(this)" style="height: 100%;" src=`+ d.cover_img + ` alt="">
                                </div>`;
                        } else {
                            return ``
                        }
                    }
                }
                , { field: 'type_text', title: '活动类型', align:'center', width:100}
                , { field: 'scene_text', title: '触发场景', align:'center'}
                , { field: 'recharge_price', title: '充值金额（元）', align:'center', width:130}
                , { field: 'currency', title: 'K币数量', align:'center', width:100}
                , { field: 'send_currency', title: '赠送币数', align:'center', width:100}
                , { field: 'sum_currency', title: '总共充值币数', align:'center', width:130}
                , { field: 'status_text', title: '状态', align:'center', width:100}
                , { field: 'start_at', title: '开始时间', align:'center', width:180}
                , { field: 'end_at', title: '结束时间', align:'center', width:180}
                , { toolbar: '#tbBar', title: '操作', width: 130, align:'center' }
            ]]
        }
        tableList(params)

        layui.use('table', function () {
            var table = layui.table;
            table.on('toolbar(activity_list)', function (obj) {
                var event = obj.event;
                if (event === 'add') {
                    x_admin_show('添加活动', './info.html', 800, 650);
                }
            });
            table.on('tool(activity_list)', function (obj) {
                var event = obj.event;
                if (event === 'del') {
                    DeleteAjax('/admin/activity/delete',{ id: obj.data.id },'activity_list')
                } else if (event === 'edit') {
                    x_admin_show('编辑活动', `./info.html?id=${obj.data.id}`, 800, 650);
                }
            });

        });

    </script>
</body>

</html>